﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DemoData.Model;
using DemoData;
using Hallenberg.Core;
using NUnit.Framework;

namespace DemoDataTest.Providers
{
    [TestFixture]
    public class CustomerProviderTest
    {
        [Test]
        public void DemoData_Providers_CustomerProvider_Create_Ok()
        {
            Customer customer = new Customer("SomeFirstName", string.Empty, "SomeLastName");

            Repository.Customers.Save(customer);

            Assert.AreNotEqual(0, customer.Id);
        }

        [Test]
        public void DemoData_Providers_CustomerProvider_Get_ApplyFirstnameFilter()
        {
            Repository.PopulateDemoData();

            foreach (Customer customer in Repository.Customers.Get().Where(customer => customer.Firstname == "John"))
            {
                Assert.AreEqual("John", customer.Firstname);
            }
        }

        [Test]
        public void DemoData_Providers_CustomerProvider_Save_Pass_Null()
        {
            var exception = Assert.Throws<ArgumentNullException>(() => Repository.Customers.Save(null));

            Assert.That(exception.ParamName, Is.EqualTo("value"));
        }

        [Test]
        public void DemoData_Providers_CustomerProvider_Save_Pass_Invalid_Customer()
        {
            var exception = Assert.Throws<ValidationException>(() => Repository.Customers.Save(new Customer("FirstName", "", "LastName") { Firstname = string.Empty }));

            Assert.That(exception, Is.Not.Null);
        }
    }
}
